package com.moleq.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.moleq.mgpos.activities.R;
import com.moleq.models.PosTender;
import com.moleq.util.MoleQUtil;

public class CashPaymentSelectionAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private List<PosTender> listItem;
	private int selectedRow = -1;
	private int mItemTextSize = 16;

	public CashPaymentSelectionAdapter(Context context, List<PosTender> listItem) {
		this.mInflater = LayoutInflater.from(context);
		this.listItem = listItem;
	}

	public void setSource(List<PosTender> listItem) {
		this.listItem = listItem;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return listItem.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listItem.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.selection_items, null);
			holder.tv_selection_name = (TextView) convertView.findViewById(R.id.tv_selection_name);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.tv_selection_name.setTextSize(mItemTextSize);
		holder.tv_selection_name.setText("Tender " + String.valueOf(listItem.get(position).index + 1) +" "+
									listItem.get(position).paymentType.getText() + " "+ MoleQUtil.fixNumber(listItem.get(position).getPt_tender()));

		if (position == selectedRow) {
			holder.tv_selection_name.setBackgroundColor(Color.rgb(255, 219, 16));
		} else {
			holder.tv_selection_name.setBackgroundColor(Color.rgb(204, 204, 204));
		}

		return convertView;
	}

	public final class ViewHolder {
		public TextView tv_selection_name;

	}

	public void ScrollToRow(int row) {
		selectedRow = row;
		this.notifyDataSetChanged();
	}

	public int GetSelectedIndex() {
		return selectedRow;
	}

	public void setItemTextSize(int size) {
		mItemTextSize = size;
		
	}
}
